import time
from time import localtime

from django.db.models.expressions import result

import dama
from selenium import webdriver
from selenium.webdriver.common.by import By
from PIL import Image

driver=webdriver.Edge()
driver.get('http://10.59.9.14:7003/')
time.sleep(2)

# 点击登录按钮
driver.find_element(By.LINK_TEXT,'登录').click()
time.sleep(2)
# 输入账号密码
driver.find_element(By.NAME,'username').send_keys('18986670716')
driver.find_element(By.NAME,'password').send_keys('a123456')
time.sleep(2)
datu=driver.save_screenshot('datu.png')
time.sleep(2)
# 获取验证码图片
# yzm=driver.find_element(By.XPATH,'//*[@id="theForm"]/div[3]/span[3]/img')
# time.sleep(2)
# localtion=yzm.location
# print(localtion)
# size=yzm.size
# print(size)
#
#
# left=localtion['x']
# top=localtion['y']
# right=left+size['width']
# bottom=top+size['height']
#
# Image=Image.open('datu.png')
# Image1=Image.crop((left*1.5,top*1.5,right*1.5,bottom*1.5))
# Image1.save('image2.png')
# dm=dama.Dama('18986670716','zxr2004.','971207')
# yzmdm=open('image2.png','rb').read()
# jieguo=dm.PostPic(yzmdm,1902)
# print(jieguo)
# result=jieguo['pic_str']
# print('我的打码结果是',result)

yzm=driver.find_element(By.XPATH,'//*[@id="theForm"]/div[3]/span[3]/img')
time.sleep(2)
localtion=yzm.location
print(localtion)
size=yzm.size
print(size)


left=localtion['x']
top=localtion['y']
right=left+size['width']
bottom=top+size['height']
# 打开大图
Image=Image.open('datu.png')
# 裁剪区域
Image1=Image.crop((left*1.5,top*1.5,right*1.5,bottom*1.5))
# 保存
Image1.save('image2.png')


dm=dama.Dama('18986670716168','zxr2004.','971207')
yzmdm=open('image2.png','rb').read()
jieguo=dm.PostPic(yzmdm,1902)
print(jieguo)
result=jieguo['pic_str']
print('我的打码结果是',result)

driver.find_element(By.XPATH,'//*[@id="theForm"]/div[3]/span[2]/input').send_keys(result)
time.sleep(2)
# 点击登录按钮
driver.find_element(By.CSS_SELECTOR,'.finish-btn').click()
time.sleep(15)
